#include <bits/stdc++.h>

using namespace std;
#define int long long
const int inf = 0x3f3f3f3f;

void solve()
{
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) cin >> a[i];
	for (int i = 0; i < n - 1; i++)
	{
		if (abs(a[i] - a[i + 1]) <= 1)
		{
			cout << 0 << endl;
			return;
		}
	}
	int ans = 1;
	for (int i = 1; i < n; i++)
	{
		int l = min(a[i], a[i - 1]);
		int r = max(a[i], a[i - 1]);
		if (i - 2 >= 0 && ((a[i - 2] >= l && a[i - 2] <= r) || (a[i - 2] + 1 >= l && a[i - 2] + 1 <= r) || (a[i - 2] - 1 >= l && a[i - 2] - 1 <= r)))
		{
			cout << ans << endl;
			return;
		}
		if (i + 1 < n && ((a[i + 1] >= l && a[i + 1] <= r) || (a[i + 1] + 1 >= l && a[i + 1] + 1 <= r) || (a[i + 1] - 1 >= l && a[i + 1] - 1 <= r)))
		{
			cout << ans << endl;
			return;
		}
	}
	cout << -1 << endl;
}

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int _ = 1;
	cin >> _;
	while (_--)
	{
		solve();
	}
	return 0;
}